<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="root">
       
    </div>
    <script src="https://unpkg.com/react@18/umd/react.development.js" crossorigin></script>
    <script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js" crossorigin></script>
    <script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>


    <script type="text/babel">
       class Student extends React.Component{
            constructor(props){
                super(props);
            }
            render(){
                return <div>
                    <Add></Add>
                    <Update></Update>
                    <Search></Search>
                    <List></List>
                </div>
            }
       }
       class Add extends React.Component{
            constructor(props){
                super(props);
            }
            render(){
                return <div>
                    <h2>增加</h2>
                    <InputElement type="text">姓名：</InputElement>
                    <InputElement type="text">年龄：</InputElement>
                    <RadioElement name="addGender">性别：</RadioElement>
                    <input type="button" value="增加" />
                </div>
            }
       }
       class Update extends React.Component{
            constructor(props){
                super(props);
            }
            render(){
                return <div>
                    <h2>修改</h2>
                    <InputElement type="text">姓名：</InputElement>
                    <InputElement type="text">年龄：</InputElement>
                    <RadioElement name="updateGender">性别：</RadioElement>
                    <input type="button" value="修改" />
                </div>
            }
       }
       class Search extends React.Component{
            constructor(props){
                super(props);
            }
            render(){
                return <div>
                    <select>
                        <option value="name">姓名</option>
                        <option value="age">年龄</option>
                        <option value="gender">性别</option>
                    </select>
                    <input type="text" />
                    <input type="button" value="搜索" />
                </div>
            }
       }
       class List extends React.Component{
            students = [{
                name:"张飞",
                age:30,
                gender:"男"
            },
            {
                name:"关羽",
                age:35,
                gender:"男"
            },
            {
                name:"小乔",
                age:20,
                gender:"女"
            }];
            constructor(props){
                super(props);
            }
            render(){
                return <div>
                    <table border="1">
                        <thead>
                            <tr>
                                <th>姓名</th>
                                <th>性别</th>
                                <th>年龄</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            {
                                this.students.map(function(stu){
                                    return <tr>
                                        <td>{stu.name}</td>
                                        <td>{stu.gender}</td>
                                        <td>{stu.age}</td>
                                        <td>
                                            <input type="button" value="修改" />
                                            <input type="button" value="删除" />
                                        </td>
                                    </tr>
                                })
                            }
                        </tbody>
                    </table>
                </div>
            }
       }
        
       class InputElement extends React.Component{
            constructor(props){
                super(props);
            }
            render(){
                return <div>
                    <label>{this.props.children}</label>
                    <input type={this.props.type} />
                    <span></span>
                </div>
            }
        }
        class RadioElement extends React.Component{
            constructor(props){
                super(props);
            }
            render(){
                return <div>
                        <label >{this.props.children}</label>
                        <input type="radio" name={this.props.name} /><label>男</label>
                        <input type="radio" name={this.props.name} /><label>女</label>
                    </div>  
            }
        }
        const root = ReactDOM.createRoot(document.getElementById("root"));
        root.render(<Student></Student>);
    </script>
</body>
</html>